package com.example.ref;


import java.io.IOException;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author Giuseppe.Longordo
 *
 */
public class DatabaseAdapter 
{
	private static final int DATABASE_VERSION =2;  
	private static final String DATABASE_NAME = "refdatabase.db";  

	private final Context context;   
	private DatabaseHelper DBHelper;  
	private SQLiteDatabase db;  

	DatabaseAdapter(Context ctx)  
	{  
		this.context = ctx;  
		try
		{
			DBHelper = new DatabaseHelper(context);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	} 
	

	//opens the database  
	public SQLiteDatabase  open() throws SQLException   
	{  
		db = DBHelper.getWritableDatabase();  
		return db;  
	}  

	//closes the database    
	public void close()   
	{  
		DBHelper.close();  
	}  



	public SQLiteDatabase getDb() {
		return db;
	}
	public static class DatabaseHelper extends SQLiteOpenHelper   
	{  
		
		public DatabaseHelper(Context context) throws IOException   
		{  
			super(context, DATABASE_NAME, null, DATABASE_VERSION);   
		}

		@Override
		public void onCreate(SQLiteDatabase arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
			// TODO Auto-generated method stub
			
		}  
	}      
}
